package midone.exchangeskill.main.view;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.RelativeLayout;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import midone.exchangeskill.R;
import midone.exchangeskill.base.dagger.AppComponent;
import midone.exchangeskill.base.view.BaseActivity;
import midone.exchangeskill.bean.IndexGoodsBean;
import midone.exchangeskill.main.adapter.MainGoodsListAdapter;
import midone.exchangeskill.main.contract.MainActivityContract;
import midone.exchangeskill.main.dagger.DaggerMainActivityComponent;
import midone.exchangeskill.main.dagger.MainActivityModule;
import midone.exchangeskill.utils.LogLog;
import midone.exchangeskill.utils.PageStateManager;
import midone.exchangeskill.utils.SharedPreferencesUtil;
import midone.exchangeskill.utils.ViewUtils;

/**
 * Created by NekoNeko on 2016/11/7.
 */

public class MainActivity extends BaseActivity implements MainActivityContract.MainActivityView {
    @Inject
    ViewUtils viewUtils;
    @Inject
    MainActivityContract.MainActivityPresenter mainActivityPresenter;
    @Inject
    SharedPreferencesUtil sharedPreferencesUtil;
    @Inject
    PageStateManager mPageStateManager;
    @BindView(R.id.content)
    RelativeLayout mContent;
    @BindView(R.id.recycle_view)
    RecyclerView mRecycleView;

    @Override
    protected void setUpComponent(AppComponent appComponent) {
        DaggerMainActivityComponent.builder().appComponent(appComponent).mainActivityModule(new MainActivityModule(this)).build().inject(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initViews();
        mainActivityPresenter.getIndexGoodsList("", "1", "1");

    }

    private void initViews() {
        mPageStateManager.initPage(mContent);
    }

    @Override
    public void showProgress(String msg) {
        mPageStateManager.showLoadingProgress(R.layout.view_progress_layout);
    }

    @Override
    public void hideProgress() {
        mPageStateManager.showContentView();
    }

    @Override
    public void onGoodsListSuccess(IndexGoodsBean indexGoodsBean) {
        LogLog.log("onGoodsListSuccess", "onGoodsListSuccess");
        mRecycleView.setLayoutManager(new LinearLayoutManager(this));
        MainGoodsListAdapter listAdapter = new MainGoodsListAdapter();
        listAdapter.setBeanList(indexGoodsBean.getData());
        mRecycleView.setAdapter(listAdapter);
        listAdapter.notifyDataSetChanged();
    }

    @Override
    public void onGoodsListFailed(String msg) {
        LogLog.log("onGoodsListFailed", "onGoodsListFailed");
        showSnackBar(msg);

    }

    @Override
    public void onGoodsListError(Throwable throwable) {
        throwable.printStackTrace();
    }
}
